//
//  ALPS_TLocalRadioViewController.m
//  Alps
//
//  Created by dllo on 16/6/13.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "ALPS_TLocalRadioViewController.h"
#import "ALPS_TComprehensiveTCell.h"
#import "ALPS_TPRadioModel.h"
@interface ALPS_TLocalRadioViewController ()<UITableViewDelegate, UITableViewDataSource>
@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, strong) NSMutableArray *dataSource;


@end

@implementation ALPS_TLocalRadioViewController

- (void)dealloc
{
    _tableView.delegate = nil;
    _tableView.dataSource = nil;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.dataSource = [NSMutableArray array];
    [self getView];
    [self getData];
    [self setLeftBackButton];
}



-(void)getView
{
    self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, ScreeWidth, ScreeHeight - 64) style:UITableViewStylePlain];
    self.tableView.dataSource = self;
    self.tableView.delegate  = self;
    self.tableView.separatorStyle = UITableViewCellSelectionStyleGray;
    [self.view addSubview:_tableView];
    [self.tableView registerClass:[ALPS_TComprehensiveTCell class] forCellReuseIdentifier:@"ALPS_TComprehensiveTCell"];
}


-(void)getData
{
    //210000
    [WSSNetTool GetNetByURL:@"http://live.ximalaya.com/live-web/v1/getRadiosListByType?pageNum=1&pageSize=20&provinceCode=210000&radioType=2" body:nil headers:nil response:0 success:^(id result) {
        NSArray *array = [result objectForKey:@"result"];
        for (NSDictionary *dic in array) {
            ALPS_TPRadioModel *model = [[ALPS_TPRadioModel alloc] initWithDic:dic];
            [self.dataSource addObject:model];
        }
        [self.tableView reloadData];
    } failure:^(NSError *error) {
        
    }];
    
    

}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 100;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.dataSource.count;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    ALPS_TComprehensiveTCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ALPS_TComprehensiveTCell"];
    cell.modelP = [self.dataSource objectAtIndex:indexPath.row];
    return cell;

}


-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{

    ALPS_PlayerMainViewController *pmVC = [[ALPS_PlayerMainViewController alloc]init];
    ALPS_TCWRadioModel *model = [self.dataSource objectAtIndex:indexPath.row];
    NSDictionary *dic = model.radioPlayUrl;
    pmVC.radioName = model.rname;
    pmVC.radioURL = [dic objectForKey:@"radio_64_aac"];
    pmVC.isRedioYesOrNo = YES;
    pmVC.pictureURL = model.radioCoverLarge;
    [self.navigationController pushViewController:pmVC animated:YES];

}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
